package demo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ConnectionPool {
	public static void main(String[] args) {
		ConnectionPool cp = new ConnectionPool();
		try {
//			cp.getData();
			cp.getData2();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void getData() throws Exception{
		Connection con = null;
		con = CreateConnection.getConnection();
		String sql = "select p_student_id from p_student where isused = 'Y' and rownum <= 2000";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			
			while (rs.next()) {
				Integer p_Student_ID = rs.getInt(1);
				Student student = new Student(p_Student_ID);
				System.out.println("==>" + student.toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				rs.close();	
			}
			if (ps != null) {
				ps.close();
			}
			con.close();
		}
	}
	
	public void getData2() throws Exception{
		Connection con = null;
		con = CreateConnection.getConnectionPool();
		String sql = "select p_student_id from p_student where isused = 'Y' and rownum <= 2000";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			
			while (rs.next()) {
				Integer p_Student_ID = rs.getInt(1);
				Student student = new Student(p_Student_ID);
				System.out.println("==>" + student.toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				rs.close();	
			}
			if (ps != null) {
				ps.close();
			}
			con.close();
		}
	}
}
